/**
 * NumberMatchingGameView
 * 
 * @author Joshua Stein
 *
 */
package edu.bu.cs673.superkids123.children.view.games;

import java.awt.Graphics;
import java.util.HashMap;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JPanel;

import edu.bu.cs673.superkids123.AbstractFrame;
import edu.bu.cs673.superkids123.AbstractNavigationView;
import edu.bu.cs673.superkids123.children.model.resources.AudioPlayer;
import edu.bu.cs673.superkids123.children.model.resources.ChildrenResource;
import edu.bu.cs673.superkids123.children.model.resources.ChildrenResourceProvider;
import edu.bu.cs673.superkids123.children.view.components.GraphicsImage;
import edu.bu.cs673.superkids123.children.view.components.ViewManager;
public class FanFairView extends AbstractNavigationView {
	
	
	private JPanel FanFairPanel;
	private ChildrenResourceProvider provider = ChildrenResourceProvider.getInstance();
	private ImageIcon background;
	private ViewManager position;
	private HashMap<String, GraphicsImage> design;
	
	private static final String[] TITLES = { "Correct... Very Good!", "All Right!", "YEAAAHHH!",
		"You're the boss!", "Monkey is happy", "Correct!", "\\(^_^)/", "Ace!", "All Star!", 
		"You're on FIRE! (not literally)", "Great!", "Excellent!" };
	
	public FanFairView(AbstractFrame mainFrame) {
		super(mainFrame);
		setDesignAndImages();
		position = new ViewManager(design);
		
	}
	@Override
	public String getTitle() {
		
		Random rand = new Random();
		int roll = Math.abs((rand.nextInt() % TITLES.length));
		
		return TITLES[roll];
	}
	@Override
	public String getBorderTitle() {
		return "";
	}
	@Override
	protected JComponent layout() {
		
		this.setAvatarVisible(false);
		this.setTitleBorderVisible(false);
		this.setParentsButtonVisible(false);
		
		FanFairPanel = new JPanel() {
			private static final long serialVersionUID = 1L;
			public void paint(Graphics g) {
				super.paint(g);
					//g.drawString("Correct", 100, 100);
					position.draw("background", g, background.getImage());	
			}
		};
		return FanFairPanel;
	}

	public void playAudio(int number) {
		AudioPlayer audioPlayer = new AudioPlayer();
		byte[] audioData = getAudioSampledData(number); 
		audioPlayer.playAudio(audioData);
		try {
			Thread.sleep(100);
		}
		catch (InterruptedException ie) {
			System.out.println("Thread interrupted");
		}
	}
	
	public byte[] getAudioSampledData(int numberToPlay) {
		byte[] audioData = null;
		audioData = provider.getAudioContentByNumber(numberToPlay);
		return audioData;
	}
	
	private void setDesignAndImages(){
		//background = provider.getImage(ChildrenResource.fanfairBackground);
		background = provider.getImage(ChildrenResource.fanfairMonkeyBackground);//provider is used here, I don't like that it exists in different code areas at random.
		design = new HashMap<String, GraphicsImage>();
// ALL DESIGN HERE
					/*put("name", new GraphicsImage("Name", pos_x, pos_y, width, height));*/
					design.put("background", new GraphicsImage("background", 0, 0, 400, 800));	
	}
// END				
}
